try {
    function webSocket(url, headers, listener) {
        let client = new OkHttpClient.Builder()
                .readTimeout(0, java.util.concurrent.TimeUnit.MILLISECONDS)
                .build();
        let requestBuilder = new Request.Builder();
        for (let headerKey in headers) {
            requestBuilder.addHeader(headerKey, headers[headerKey]);
        }
        requestBuilder.url(url);
        let request = requestBuilder.build();
        return client.newWebSocket(request, listener);
    }

    let webSocketListener = new JavaAdapter(WebSocketListener, {
        onOpen: (webSocket, response) => {
            console.log("连接：" + response);
        },
        onMessage: (webSocket, data) => {
            console.log("接收到数据：" + data);
        },
        onClosing: (webSocket, code, reason) => {
            console.log("关闭连接： code=%s, reason=%s", code, reason);
        },
        onClosed: (webSocket, code, reason) => {
            console.log("关闭连接： code=%s, reason=%s", code, reason);
        },
        onFailure: (webSocket, throwable, response) => {
            console.log("发生异常:" + throwable);
        }
    });

    let headers = {
        "Origin": "http://coolaf.com"
    };

    let ws = new webSocket("ws://123.207.136.134:9010/ajaxchattest", headers, webSocketListener);
    ws.send("你好"); // 发送文字
    sleep(1000);
    ws.send(new java.lang.String("🐱").getBytes()); // 发送字节
    sleep(1000);
    ws.close(1000, "我就是要关闭"); // 等待未发送消息发生完后，关闭连接
    sleep(1000);
    ws.cancel();    // 直接强关

} catch (e) {
    console.trace(e)
}

log(WebSocketListener)